package com.mgfireworks.mgplatform.mgadmin.user;

import cn.hn.java.summer.annotation.ParamValid;
import com.mgfireworks.mgplatform.mgadmin.user.model.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

/**
 * 
 * @author nap
 * 20161015-10:19:48
 * 用户角色控制器
 */
@Controller
@RequestMapping("/user/role")
public class RoleController {

	@Autowired
	RoleService roleService;
	
	/**
	 * 用户角色列表
	 * @return
	 */
	@RequestMapping("/list")
	public List<Role> list(Role p){
		return roleService.getRoles(p);
	}

	/**
	 * 用户角色选择列表
	 * @return
	 */
	@RequestMapping("/select")
	public List<Role> selectList(Role p){
		return roleService.getRoles(p);
	}

	/**
	 * 添加用户角色
	 */
	@RequestMapping(value="/add",method=RequestMethod.GET)
	public void add(){
	}
	
	/**
	 * 提交添加用户角色
	 */
	@RequestMapping(value="/add",method=RequestMethod.POST)
	public void postAdd(@ParamValid Role p){
		roleService.addRole(p);
	}

	/**
	 * 编辑用户角色
	 */
	@RequestMapping(value="/edit",method=RequestMethod.GET)
	public Role edit(Role p){
		return roleService.getRole(p);
	}
	
	/**
	 * 提交编辑用户角色
	 */
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	public void postEdit(@ParamValid Role p){
		roleService.editRole(p);
	}
	
	/**
	 * 获取用户角色
	 */
	@RequestMapping(value="/get",method=RequestMethod.GET)
	public Role get(Role p){
		return roleService.getRole(p);
	}
	
	/**
	 * 删除用户角色
	 */
	@RequestMapping("/del")
	public void del(Role p){
		roleService.delRole(p);
	}
}